package cn.edu.hy.demo06.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("sys")
public class LoginController {

    @GetMapping("login")
    public ModelAndView login(){

        return new ModelAndView("demo06/login");
    }

    @PostMapping("login")
    public ModelAndView postLogin(String userName ,String passWord ,HttpServletRequest request,HttpServletResponse response){

        if (StringUtils.isEmpty(userName)||StringUtils.isEmpty(passWord)) {
            return new ModelAndView("demo06/login");
        }else if(userName.equals("admin")&&passWord.equals("123456")){
            //书写登录逻辑
            request.getSession().setAttribute("token","1334142343254654084543u8934yu53y");
            return new ModelAndView("demo06/index");
        }else {
            return new ModelAndView("demo06/login");
        }
    }


}
